home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Manage2.aspx.cs616 < prev    next >
Text File  |  2008-04-10  |  24KB  |  547 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.Caching;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using GBPVR.Public;
  9. using GBPVRSchedule;
  10. using gbweb.classes;
  11.  
  12. namespace gbweb
  13. {
  14.     /// <summary>
  15.     /// Summary description for Manage.
  16.     /// </summary>
  17.     public partial class Manage2 : Page
  18.     {
  19.  
  20.         private Settings guideParams;
  21.         protected string programUniqueIdentifier;
  22.  
  23.         private string sortOrder;
  24.         private ArrayList sortOrders;
  25.  
  26.         private int recordingTypeFilter;
  27.  
  28.         private HttpCookie cookie;
  29.  
  30.         protected ProgramTreeItem[] pgmTree;
  31.         protected int treeIdx;
  32.         private IList myScheduledRecordings;
  33.  
  34.         private Channel channel;
  35.  
  36.         private ArrayList displayScheduleSort = new ArrayList();
  37.         Hashtable channelCache = new Hashtable();
  38.  
  39.         protected void Page_PreRender(object sender, System.EventArgs e)
  40.         {
  41.             //Call the common routine for loading the page with data
  42.             processViews();
  43.  
  44.             if (mr_searchResults.SelectedValue == "tree")
  45.             {
  46.                 hlDelete.Visible = false;
  47.             }
  48.             else
  49.             {
  50.                 //Guest Users do not get access to initiatie, delete or cancel recordings. 
  51.                 if (Convert.ToBoolean((string)Session["NotGuestUser"]))
  52.                 {
  53.                     hlDelete.Visible = true;
  54.                 }
  55.                 else
  56.                 {
  57.                     hlDelete.Visible = false;
  58.                 }
  59.             }
  60.         }
  61.  
  62.         protected void Page_Load(object sender, EventArgs e)
  63.         {
  64.             #region Page Load code that is common to both the TreeView and TableView
  65.             Session["GuideStartTime"] = null;
  66.             
  67.             guideParams = Global.Settings;
  68.  
  69.             //Code to prevent Guest users from accessing the Admin and search Pages
  70.             if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
  71.             {
  72.                 NAV_SEARCH.Visible = false;
  73.                 NAV_CONFIG.Visible = false;
  74.             }
  75.  
  76.             treeIdx = 0;
  77.             pgmTree = new ProgramTreeItem[1000];
  78.  
  79.             //Read in the recording filter settings from the cookie
  80.             cookie = Request.Cookies["recordingTypeFilter"]; ;
  81.  
  82.             //Set the recording filters based off of what was found in the cookie
  83.             recordingTypeFilter = cookie != null ? Convert.ToInt32(cookie.Value) : 0xffbf;
  84.             
  85.             //Check to see if the user selected the option for all filters or no filters and set the filter value accordingly
  86.             if (recordingTypes.SelectedValue == "all")
  87.             {
  88.                 recordingTypeFilter = 65535;
  89.                 //Set all the filter select boxes to true
  90.                 for (int a = 0; a < recordingTypes.Items.Count; a++)
  91.                 {
  92.                     recordingTypes.Items[a].Selected = true;
  93.                 }
  94.                 //Uncheck the All and None options
  95.                 recordingTypes.Items[0].Selected = false; 
  96.                 recordingTypes.Items[1].Selected = false;
  97.             }
  98.             else if (recordingTypes.SelectedValue == "none")
  99.             {
  100.                 recordingTypeFilter = 65408;
  101.                 //Set all the filter select boxes to false
  102.                 for (int a = 0; a < recordingTypes.Items.Count; a++)
  103.                 {
  104.                     recordingTypes.Items[a].Selected = false;
  105.                 }
  106.             }
  107.             checkRecordingType(ref recordingTypeFilter, "Pending", ScheduledRecording.STATUS_PENDING);
  108.             checkRecordingType(ref recordingTypeFilter, "In Progress", ScheduledRecording.STATUS_IN_PROGRESS);
  109.             checkRecordingType(ref recordingTypeFilter, "Available", ScheduledRecording.STATUS_COMPLETED);
  110.             checkRecordingType(ref recordingTypeFilter, "Failed", ScheduledRecording.STATUS_COMPLETED_WITH_ERROR);
  111.             checkRecordingType(ref recordingTypeFilter, "Conflict", ScheduledRecording.STATUS_CONFLICT);
  112.             checkRecordingType(ref recordingTypeFilter, "Reoccurring", ScheduledRecording.STATUS_PLACE_HOLDER);
  113.             checkRecordingType(ref recordingTypeFilter, "Deleted", ScheduledRecording.STATUS_DELETED);
  114.             
  115.             //Update the cookie with what is found in the recording filters for the next display
  116.             cookie = new HttpCookie("recordingTypeFilter", recordingTypeFilter.ToString());
  117.             cookie.Expires = DateTime.Now.AddYears(1);
  118.             Response.Cookies.Add(cookie);
  119.  
  120.             //Clear out the listings area so that you don't get leftovers from the previous display
  121.             CONTENTS.InnerHtml = "";
  122.  
  123.             //Only execute on the first page load
  124.             if (!IsPostBack)
  125.             {
  126.                 //Set the Day/date/time display on the header
  127.                 viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
  128.                 serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
  129.  
  130.                 //Set the header tab of the Manage Recordings to active
  131.                 NAV_RECORDINGS.Attributes.Add("class", "currentTab");
  132.                 NAV_RECORDINGS.Visible = guideParams.showManage;
  133.                 if (Convert.ToBoolean((string)Session["NotGuestUser"]))
  134.                 {
  135.                     NAV_SEARCH.Visible = guideParams.showSearch;
  136.                 }
  137.                 NAV_VIDEO.Visible = guideParams.showVideoLib;
  138.                 NAV_MUSIC.Visible = guideParams.showMusicLib;
  139.                 NAV_PHOTO.Visible = guideParams.showPhotoLib;
  140.                 NAV_STATS.Visible = guideParams.showStats;
  141.  
  142.                 //Set the magic RSS links so IE and Firefox can sense the available RSS feeds
  143.                 string url =
  144.                     Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
  145.                                                    Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  146.                 try
  147.                 {
  148.                     url = url.Substring(0, url.IndexOf("/gbpvr/"));
  149.                 }
  150.                 catch
  151.                 {
  152.                     url = url.Substring(0, url.IndexOf("/gbweb/"));
  153.                 }
  154.  
  155.                 in_progressLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=in-progress");
  156.                 completedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=completed");
  157.                 pendingLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=pending");
  158.                 conflictLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=conflict");
  159.                 failedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=failed");
  160.                 seasonLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=season");
  161.                 deletedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=deleted");
  162.  
  163.                 cookie = Request.Cookies["mr_showSearchResults"];
  164.                 mr_searchResults.SelectedValue = cookie != null ? cookie.Value : "table";
  165.  
  166.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  167.                 //options otherwise do not show them
  168.                 if (mr_searchResults.SelectedValue == "tree")
  169.                 {
  170.                     treeControl.Visible = true;
  171.                     sortResults.Visible = true;
  172.                     sortResults2.Visible = true;
  173.  
  174.                     //If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
  175.                     //and for original air date secondary sort
  176.                     if (ExtendedEWA.Initialize())
  177.                     {
  178.                         ListItem starRating = new ListItem();
  179.                         starRating.Text = "Star Rating";
  180.                         starRating.Value = "mr_star";
  181.                         srtOrder.Items.Add(starRating);
  182.  
  183.                         ListItem originalAirDate = new ListItem();
  184.                         originalAirDate.Text = "Original Air Date (oad)";
  185.                         originalAirDate.Value = "mr_original_date";
  186.                         srtOrder.Items.Add(originalAirDate);
  187.                     }
  188.  
  189.                     //Set the selected search order to whatever was used the last time
  190.                     cookie = Request.Cookies["mr_SortOrder"];
  191.                     srtOrder.SelectedValue = cookie != null ? cookie.Value : "mr_title";
  192.  
  193.                     cookie = Request.Cookies["mr_SecondarySortOrder"];
  194.                     sec_srtOrder.SelectedValue = cookie != null ? cookie.Value : "mrs_title";
  195.  
  196.                 }
  197.                 else
  198.                 {
  199.                     treeControl.Visible = false;
  200.                     sortResults.Visible = false;
  201.                     sortResults2.Visible = false;
  202.                 }
  203.             }
  204.             else
  205.             {
  206.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  207.                 //options otherwise do not show them
  208.                 if (mr_searchResults.SelectedValue == "tree")
  209.                 {
  210.                     sortResults.Visible = true;
  211.                     sortResults2.Visible = true;
  212.                     treeControl.Visible = true;
  213.  
  214.                     //Store the selected sort order in the cookie for the next search
  215.                     cookie = new HttpCookie("mr_SortOrder", srtOrder.SelectedValue);
  216.                     cookie.Expires = DateTime.Now.AddYears(1);
  217.                     Response.Cookies.Add(cookie);
  218.  
  219.                     //Store the selected secondary sort order in the cookie for the next search
  220.                     cookie = new HttpCookie("mr_SecondarySortOrder", sec_srtOrder.SelectedValue);
  221.                     cookie.Expires = DateTime.Now.AddYears(1);
  222.                     Response.Cookies.Add(cookie);
  223.  
  224.                 }
  225.                 else
  226.                 {
  227.                     treeControl.Visible = false;
  228.                     sortResults.Visible = false;
  229.                     sortResults2.Visible = false;
  230.                 }
  231.  
  232.                 //Store the selected display (table or tree) in the cookie for the next search
  233.                 //
  234.                 //Commented out the write of the cookie since we are only using a forced table view
  235.                 //un-comment when TreeView is added back in
  236.                 //
  237.                 cookie = new HttpCookie("mr_showSearchResults", mr_searchResults.SelectedValue);
  238.                 cookie.Expires = DateTime.Now.AddYears(1);
  239.                 Response.Cookies.Add(cookie);
  240.             }
  241.  
  242.             //Read the cookie for the sort order of the display
  243.             cookie = Request.Cookies["sortOrder"];
  244.             sortOrder = cookie != null ? cookie.Value.Trim(',') : "datetime,channel,title,status";
  245.             sortOrders = new ArrayList(sortOrder.Split(','));
  246.             string newSort = Request["sort"];
  247.             if (newSort != null)
  248.             {
  249.                 if (sortOrders.Contains(newSort))
  250.                 {
  251.                     if (sortOrders[0].ToString() == newSort)
  252.                     {
  253.                         sortOrders.Remove(newSort);
  254.                         sortOrders.Insert(0, newSort + " desc");
  255.                     }
  256.                     else
  257.                     {
  258.                         sortOrders.Remove(newSort);
  259.                         sortOrders.Insert(0, newSort);
  260.                     }
  261.                 }
  262.                 else
  263.                 {
  264.                     sortOrders.Remove(newSort + " desc");
  265.                     sortOrders.Insert(0, newSort);
  266.                 }
  267.             }
  268.             sortOrder = string.Join(",", (string[])sortOrders.ToArray(typeof(string)));
  269.             
  270.             //Update the sort settings in the cookie for the next display
  271.             cookie = new HttpCookie("sortOrder", sortOrder);
  272.             cookie.Expires = DateTime.Now.AddYears(1);
  273.             Response.Cookies.Add(cookie);
  274.  
  275.             //Store the selected display (table or tree) in the cookie for the next search
  276.             cookie = new HttpCookie("mr_showSearchResults", mr_searchResults.SelectedValue);
  277.             cookie.Expires = DateTime.Now.AddYears(1);
  278.             Response.Cookies.Add(cookie);
  279.  
  280.             #endregion
  281.  
  282.             FILTERS.Visible = true;
  283.         }
  284.  
  285.  
  286.         #region Page Load code for common processing of views - processViews
  287.         private void processViews()
  288.         {
  289.             //Turn on the appropriate display elements while turning off the one not being used
  290.             if (mr_searchResults.SelectedValue == "table")
  291.             {
  292.                 RECORDINGS_HEADER.Visible = true;
  293.                 SORT_HEADER.Visible = false;
  294.             }
  295.             else
  296.             {
  297.                 forcedScrollbar.InnerHtml = "";
  298.                 SORT_HEADER.Visible = true;
  299.                 RECORDINGS_HEADER.Visible = false;
  300.             }
  301.             
  302.             //Create a new schedulehelper object to process all the found recordings (all types)
  303.             Schedule scheduleHelper = Global.Schedule;
  304.             ProgrammeDisplay2 displayProgramme = new ProgrammeDisplay2();
  305.  
  306.             //Remove a programme if someone clicked on Cancel prior t loading the list of programmes so that it is gone and does not appear again
  307.             string cancel = Request.Params["cancel"];
  308.             if ((cancel != null) && (cancel.Length > 0))
  309.             {
  310.                 ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(cancel));
  311.                 if (scheduledRecording != null)
  312.                 {
  313.                     scheduleHelper.CancelScheduledRecording(scheduledRecording);
  314.                 }
  315.             }
  316.  
  317.             //Create a list of all of the recordings that are found
  318.             myScheduledRecordings = scheduleHelper.LoadRecordingSchedule();
  319.  
  320.             //Verify that the object holding all of the recordings is an arraylist and if so sort it in the order the user has selected
  321.             //if (myScheduledRecordings is ArrayList)
  322.             //    ((ArrayList)myScheduledRecordings).Sort(new RecordingComparer(sortOrders, channelCache));
  323.  
  324.             //Verify the user has VLC installed by looking for it in the path that is set in the config
  325.             bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
  326.  
  327.             CSSProgrammeTableLoad tableLoad = new CSSProgrammeTableLoad();
  328.             Type pageType = Type.GetType("gbweb.Manage2");
  329.             displayScheduleSort = new ArrayList();
  330.             //Iterate through each recording to load it to the appropriate display format
  331.             foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
  332.             {
  333.                 //Determine the status of the currect scheduled programme
  334.                 int flag = (int) Math.Pow(2, scheduledRecording.getRecordingStatus());
  335.                 //If the recording status of the current scheduled programme does not match the recording filter then we do not need to look at this schedule
  336.                 //so we jump out of the foreach loop
  337.                 if ((recordingTypeFilter & flag) == 0) continue;
  338.  
  339.                 //Instantiate a programme object for this schedule
  340.                 Programme programme = scheduledRecording.getProgramme();
  341.                 channel = scheduleHelper.GetChannelByOID(scheduledRecording.getChannelOID());
  342.  
  343.                 //Call the appropriate method for completing the processing of the view
  344.                 if (mr_searchResults.SelectedValue == "table")
  345.                 {
  346.                     //We load the programme from the scheduled recording to an array so that we can sort them into the correct order after we have all
  347.                     //the programs from all the recordings
  348.                     displayScheduleSort.Add(scheduledRecording); 
  349.                     //tableLoad.processTable(pageType, channelCache, sortOrders, Cache, Request, Server, displayProgramme, strmAllowed, programme, scheduledRecording, false);
  350.                 }
  351.                 else
  352.                 {
  353.                     processTree(displayProgramme, programme, scheduledRecording);
  354.                 }
  355.             }
  356.  
  357.             if (mr_searchResults.SelectedValue == "tree")
  358.             {
  359.                 //Resize the array of ProgrammeTreeItems so that is isn't hogging up space.
  360.                 Array.Resize(ref pgmTree, treeIdx);
  361.                 //TreeView1.CollapseAll();
  362.                 TreeView1.Nodes.Clear();
  363.                 //TreeView1.SelectedNode.CollapseAll();
  364.                 TreeView1.Dispose();
  365.                 //Fill the TreView Control with all the nodes in the correct format
  366.                 displayProgramme.FillProgrammeTree(TreeView1, pgmTree, srtOrder.SelectedValue, sec_srtOrder.SelectedValue);
  367.  
  368.                 displayProgramme.Dispose();
  369.             }
  370.             else
  371.             {
  372.                 //Sort the matching programmes into the choosen sort order
  373.                 tableLoad.sortDisplay(sortOrders, displayScheduleSort, true);
  374.  
  375.                 //Format the now sorted matching results into the CSS table format
  376.                 IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
  377.                 while (displayScheduleSort.Count > 0)
  378.                 {
  379.                     ScheduledRecording scheduledRecording = (ScheduledRecording) displayScheduleSort[0];
  380.                     Programme pgm = scheduledRecording.getProgramme();
  381.                     tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, displayProgramme, strmAllowed, pgm, scheduledRecording, false);
  382.                     displayScheduleSort.RemoveAt(0);
  383.                 }
  384.  
  385.                 //Call the finalize process for creating the TableView
  386.                 tableLoad.processTable(pageType, sortOrders, Cache, Request, Server, null, strmAllowed, null, null, true);
  387.  
  388.                 forcedScrollbar.InnerHtml = tableLoad.getForcedScrollBar();
  389.                 CONTENTS.InnerHtml = tableLoad.getContents();
  390.                 tableLoad.Dispose();
  391.                 CONTENTS.Attributes.Add("onscroll", "fScroll(this)");
  392.             }
  393.         }
  394.         #endregion
  395.  
  396.         //This is the routine used to filter out shows that do not match the recording type filter
  397.         private void checkRecordingType(ref int recordingTypeFilter, string text, int value)
  398.         {
  399.             ListItem item = recordingTypes.Items.FindByValue(value.ToString());
  400.             int flag = (int)Math.Pow(2, value);
  401.             if (item == null)
  402.             {
  403.                 item = new ListItem(text, value.ToString());
  404.                 recordingTypes.Items.Add(item);
  405.                 item.Selected = (recordingTypeFilter & flag) != 0;
  406.             }
  407.             else
  408.             {
  409.                 if (item.Selected)
  410.                     recordingTypeFilter = recordingTypeFilter | flag;
  411.                 else
  412.                     recordingTypeFilter = recordingTypeFilter & (0xffff - flag);
  413.             }
  414.         }
  415.  
  416.         protected void hlDelete_Click(object sender, System.EventArgs e)
  417.         {
  418.             //Create a new schedulehelper object to process all the found recordings (all types)
  419.             Schedule scheduleHelper = Global.Schedule;
  420.  
  421.             foreach (string param in Request.Params.Keys)
  422.             {
  423.                 if (param.StartsWith("item"))
  424.                 {
  425.                     ScheduledRecording scheduledRecording =
  426.                         scheduleHelper.GetScheduledRecordingByOID(int.Parse(param.Substring(4)));
  427.                     if (scheduledRecording != null)
  428.                     {
  429.                         scheduleHelper.CancelScheduledRecording(scheduledRecording);
  430.                     }
  431.                 }
  432.             }
  433.         }
  434.  
  435.         #region Page Load code for the TreView - ProcessTree
  436.         //This is the main driver routine for loading the Treeview array
  437.         private void processTree(ProgrammeDisplay2 displayProgramme, Programme programme, ScheduledRecording scheduledRecording)
  438.         {
  439.             //Create a ProgrammeTreeItem to be loaded with the correct display information for the program
  440.             ProgramTreeItem treeItem = new ProgramTreeItem();
  441.             displayProgramme.FillProgrammeTreeArrayItem(treeItem, Server, programme, scheduledRecording, true, channel);
  442.             //Add the loaded ProgrammeTreeITem to the Array
  443.             pgmTree[treeIdx] = treeItem;
  444.             treeIdx = treeIdx + 1;
  445.         }
  446.         #endregion
  447.  
  448.         #region Channel Icon procssing logic
  449.         private static string channelIconPath;
  450.         private static string[] channelIconExtensions;
  451.  
  452.         public string GetChannelIcon(int channelNumber, string[] channelNames)
  453.         {
  454.             // Get the Channel Icon Directory
  455.             if (channelIconPath == null)
  456.             {
  457.                 lock (typeof(Manage2))
  458.                 {
  459.                     if (channelIconPath == null)
  460.                     {
  461.                         channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
  462.                         channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
  463.                     }
  464.                 }
  465.             }
  466.             
  467.             Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
  468.             if (channelIconCache == null)
  469.             {
  470.                 lock (typeof(Manage2))
  471.                 {
  472.                     channelIconCache = (Hashtable)Cache["channelIconCache"];
  473.                     if (channelIconCache == null)
  474.                     {
  475.                         channelIconCache = new Hashtable();
  476.                         Cache.Add(
  477.                             "channelIconCache",
  478.                             channelIconCache,
  479.                             new CacheDependency(channelIconPath),
  480.                             DateTime.MaxValue,
  481.                             Cache.NoSlidingExpiration,
  482.                             CacheItemPriority.Normal,
  483.                             null);
  484.                     }
  485.                 }
  486.             }
  487.  
  488.             if (channelIconCache.ContainsKey(channelNumber))
  489.             {
  490.                 return (string)channelIconCache[channelNumber];
  491.             }
  492.  
  493.             lock (channelIconCache)
  494.             {
  495.                 if (channelIconCache.ContainsKey(channelNumber))
  496.                 {
  497.                     return (string)channelIconCache[channelNumber];
  498.                 }
  499.  
  500.                 string channelIconFile = null;
  501.                 foreach (string channelName in channelNames)
  502.                 {
  503.                     foreach (string channelIconExtension in channelIconExtensions)
  504.                     {
  505.                         string cleanName = channelName;
  506.                         while (cleanName.Contains("/"))
  507.                         {
  508.                             cleanName = channelName.Remove(channelName.IndexOf('/'), 1);
  509.                         }
  510.                         string probeFile = cleanName + "." + channelIconExtension;
  511.                         if (File.Exists(Path.Combine(channelIconPath, probeFile)))
  512.                         {
  513.                             channelIconFile = probeFile;
  514.                             break;
  515.                         }
  516.                     }
  517.                     if (channelIconFile != null) break;
  518.                 }
  519.                 channelIconCache[channelNumber] = channelIconFile;
  520.                 return channelIconFile;
  521.             }
  522.         }
  523.         #endregion
  524.  
  525.         #region Web Form Designer generated code
  526.         override protected void OnInit(EventArgs e)
  527.         {
  528.             //
  529.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  530.             //
  531.             InitializeComponent();
  532.             base.OnInit(e);
  533.         }
  534.  
  535.         /// <summary>
  536.         /// Required method for Designer support - do not modify
  537.         /// the contents of this method with the code editor.
  538.         /// </summary>
  539.         private void InitializeComponent()
  540.         {
  541.  
  542.         }
  543.         #endregion
  544.  
  545.     }
  546. }
  547.